package com.lxz.shardingjdbcdemo.controller;

import com.lxz.shardingjdbcdemo.dao.UserTypeMapper;
import com.lxz.shardingjdbcdemo.model.UserType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user-types")
public class UserTypeController {

    @Resource
    private UserTypeMapper userTypeMapper;

    /**
     * 添加用户类型
     */
    @PostMapping("/add")
    public String addUserType(@RequestBody UserType userType) {
        userTypeMapper.insert(userType);
        return "User type added successfully";
    }

    /**
     * 获取所有用户类型
     */
    @GetMapping("/all")
    public List<UserType> getAllUserTypes() {
        return userTypeMapper.selectList(null);
    }

    /**
     * 根据ID获取用户类型
     */
    @GetMapping("/{typeId}")
    public UserType getUserTypeById(@PathVariable Long typeId) {
        return userTypeMapper.selectById(typeId);
    }
}